package cn.edu.scau.cmi.yangjiamin.client;

import cn.edu.scau.cmi.yangjiamin.factory.AutoInsurance;
import cn.edu.scau.cmi.yangjiamin.factory.BodyPolicy;
import cn.edu.scau.cmi.yangjiamin.factory.CarPolicy;
import cn.edu.scau.cmi.yangjiamin.factory.ComPolicy;
import cn.edu.scau.cmi.yangjiamin.factory.PersonPolicy;
import cn.edu.scau.cmi.yangjiamin.factory.PolicyProducer;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;

public class FactoryGUI extends Application{
	@Override
	public void start(Stage primaryStage) throws Exception{
		BorderPane pane = new BorderPane();
		BorderPane paneCenter = new BorderPane();
		ImageView imageView = new ImageView(new Image("image/photo.jpg"));
	    paneCenter.setLeft(imageView);
	    VBox vbox = new VBox(15);
	    vbox.setPadding(new Insets(5,5,5,5));
		String s = "学号：201616030128  姓名：杨嘉敏";
		Text textPerson = new Text(100, 100, s);
		HBox hbox = new HBox(15);
		hbox.setPadding(new Insets(5,5,5,5));
		Label label = new Label("请选择保险类型");
		ComboBox<String> cbo = new ComboBox<>();
		cbo.getItems().addAll("身体受伤", "汽车损坏", "人员伤亡", "多种事故");
		cbo.setStyle("fx-color: red");
		//cbo.setValue("身体受伤");
		hbox.getChildren().addAll(label, cbo);
		Button show = new Button("显示保险信息");
		vbox.getChildren().addAll(textPerson, hbox, show);
		paneCenter.setCenter(vbox);
		pane.setTop(paneCenter);
		Text textInsurance = new Text(100,100, "显示保险的详细信息");
		pane.setCenter(textInsurance);
		
		cbo.setOnAction(e->{
			String type =  cbo.getValue();
			//System.out.println(option);
			show.setOnAction(e1->{
				PolicyProducer pp = null;
				if(type == "身体受伤") pp = new BodyPolicy();
				else if(type == "汽车损坏") pp = new CarPolicy();
				else if(type == "人员伤亡") pp = new PersonPolicy();
				else pp = new ComPolicy();
				AutoInsurance ai = pp.getInsurObj();
				String desc = ai.getInsurInfo();
				textInsurance.setText(desc);
			});
			
			
		});
		
		
		
		Scene scene = new Scene(pane, 600, 500);
		primaryStage.setTitle("Factory");
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}

}
